using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Security.Permissions;


namespace App
{
    internal partial class Msg : Form
    {
        int timeout = 10;


        private System.ComponentModel.IContainer components = null;
        private Pan pan1;
        private System.Windows.Forms.Label lbH;
        private Pan pan2;
        private System.Windows.Forms.PictureBox pb;
        private System.Windows.Forms.Timer timer1;
        private BtnLb lbTimeout;
        private Panel panel3;
        private Btn btnNo;
        private Btn btnYes;
        private BtnLb lbD;
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.pan2 = new App.Pan();
            this.lbD = new App.BtnLb();
            this.pb = new System.Windows.Forms.PictureBox();
            this.lbTimeout = new App.BtnLb();
            this.pan1 = new App.Pan();
            this.lbH = new System.Windows.Forms.Label();
            this.panel3 = new System.Windows.Forms.Panel();
            this.btnNo = new App.Btn();
            this.btnYes = new App.Btn();
            this.pan2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pb)).BeginInit();
            this.pan1.SuspendLayout();
            this.panel3.SuspendLayout();
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // pan2
            // 
            this.pan2.BackColor = System.Drawing.Color.White;
            this.pan2.ColorBorder = System.Drawing.Color.Transparent;
            this.pan2.ColorDrawButton = false;
            this.pan2.ColorDrawTop = false;
            this.pan2.ColorLeftTop = System.Drawing.Color.White;
            this.pan2.ColorRightBotton = System.Drawing.Color.FromArgb(((int)(((byte)(218)))), ((int)(((byte)(234)))), ((int)(((byte)(255)))));
            this.pan2.Controls.Add(this.lbD);
            this.pan2.Controls.Add(this.pb);
            this.pan2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.pan2.DrawBackgroud = false;
            this.pan2.DrawBorder = false;
            this.pan2.Location = new System.Drawing.Point(0, 35);
            this.pan2.Name = "pan2";
            this.pan2.Size = new System.Drawing.Size(508, 211);
            this.pan2.TabIndex = 1;
            // 
            // lbD
            // 
            this.lbD.BackColor = System.Drawing.Color.Transparent;
            this.lbD.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(21)))), ((int)(((byte)(66)))), ((int)(((byte)(139)))));
            this.lbD.Isflat = true;
            this.lbD.Ispressed = false;
            this.lbD.Location = new System.Drawing.Point(153, 6);
            this.lbD.Margin = new System.Windows.Forms.Padding(1);
            this.lbD.Name = "lbD";
            this.lbD.Padding = new System.Windows.Forms.Padding(2);
            this.lbD.Size = new System.Drawing.Size(349, 128);
            this.lbD.TabIndex = 6;
            this.lbD.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // pb
            // 
            this.pb.BackColor = System.Drawing.Color.Transparent;
            this.pb.Image = global::App.Properties.Resources.Inf;
            this.pb.Location = new System.Drawing.Point(12, 6);
            this.pb.Name = "pb";
            this.pb.Size = new System.Drawing.Size(128, 128);
            this.pb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.pb.TabIndex = 0;
            this.pb.TabStop = false;
            // 
            // lbTimeout
            // 
            this.lbTimeout.BackColor = System.Drawing.Color.Transparent;
            this.lbTimeout.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbTimeout.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(21)))), ((int)(((byte)(66)))), ((int)(((byte)(139)))));
            this.lbTimeout.Isflat = true;
            this.lbTimeout.Ispressed = false;
            this.lbTimeout.Location = new System.Drawing.Point(10, 13);
            this.lbTimeout.Margin = new System.Windows.Forms.Padding(1);
            this.lbTimeout.Name = "lbTimeout";
            this.lbTimeout.Padding = new System.Windows.Forms.Padding(2);
            this.lbTimeout.Size = new System.Drawing.Size(148, 23);
            this.lbTimeout.TabIndex = 5;
            this.lbTimeout.Text = "10";
            this.lbTimeout.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // pan1
            // 
            this.pan1.ColorBorder = System.Drawing.Color.FromArgb(((int)(((byte)(218)))), ((int)(((byte)(234)))), ((int)(((byte)(255)))));
            this.pan1.ColorDrawButton = false;
            this.pan1.ColorDrawTop = false;
            this.pan1.ColorLeftTop = System.Drawing.Color.FromArgb(((int)(((byte)(218)))), ((int)(((byte)(234)))), ((int)(((byte)(255)))));
            this.pan1.ColorRightBotton = System.Drawing.Color.FromArgb(((int)(((byte)(77)))), ((int)(((byte)(123)))), ((int)(((byte)(200)))));
            this.pan1.Controls.Add(this.lbH);
            this.pan1.Dock = System.Windows.Forms.DockStyle.Top;
            this.pan1.DrawBackgroud = false;
            this.pan1.DrawBorder = false;
            this.pan1.Location = new System.Drawing.Point(0, 0);
            this.pan1.Name = "pan1";
            this.pan1.Size = new System.Drawing.Size(508, 35);
            this.pan1.TabIndex = 0;
            // 
            // lbH
            // 
            this.lbH.BackColor = System.Drawing.Color.Transparent;
            this.lbH.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lbH.Font = new System.Drawing.Font("Verdana", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
            this.lbH.ForeColor = System.Drawing.Color.Maroon;
            this.lbH.Location = new System.Drawing.Point(0, 0);
            this.lbH.Name = "lbH";
            this.lbH.Size = new System.Drawing.Size(508, 35);
            this.lbH.TabIndex = 0;
            this.lbH.Text = "Caption";
            this.lbH.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // panel3
            // 
            this.panel3.BackColor = System.Drawing.Color.Transparent;
            this.panel3.Controls.Add(this.btnNo);
            this.panel3.Controls.Add(this.lbTimeout);
            this.panel3.Controls.Add(this.btnYes);
            this.panel3.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel3.Location = new System.Drawing.Point(0, 193);
            this.panel3.Name = "panel3";
            this.panel3.Size = new System.Drawing.Size(508, 53);
            this.panel3.TabIndex = 4;
            // 
            // btnNo
            // 
            this.btnNo.ActiveColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(214)))), ((int)(((byte)(225)))));
            this.btnNo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(234)))), ((int)(((byte)(248)))));
            this.btnNo.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(106)))), ((int)(((byte)(185)))), ((int)(((byte)(232)))));
            this.btnNo.BorderThickness = 0;
            this.btnNo.ConfirmationRequired = false;
            this.btnNo.ConfirmedBackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(231)))), ((int)(((byte)(248)))), ((int)(((byte)(228)))));
            this.btnNo.ConfirmedBorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(159)))), ((int)(((byte)(227)))), ((int)(((byte)(142)))));
            this.btnNo.FlashColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(148)))), ((int)(((byte)(138)))));
            this.btnNo.HighlightColor = System.Drawing.Color.FromArgb(((int)(((byte)(201)))), ((int)(((byte)(224)))), ((int)(((byte)(235)))));
            this.btnNo.Location = new System.Drawing.Point(323, 13);
            this.btnNo.Name = "btnNo";
            this.btnNo.Size = new System.Drawing.Size(75, 23);
            this.btnNo.TabIndex = 1;
            this.btnNo.Text = "No";
            this.btnNo.Click += new System.EventHandler(this.btnNo_Click);
            // 
            // btnYes
            // 
            this.btnYes.ActiveColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(214)))), ((int)(((byte)(225)))));
            this.btnYes.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(234)))), ((int)(((byte)(248)))));
            this.btnYes.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(106)))), ((int)(((byte)(185)))), ((int)(((byte)(232)))));
            this.btnYes.BorderThickness = 0;
            this.btnYes.ConfirmationRequired = true;
            this.btnYes.ConfirmedBackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(231)))), ((int)(((byte)(248)))), ((int)(((byte)(228)))));
            this.btnYes.ConfirmedBorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(159)))), ((int)(((byte)(227)))), ((int)(((byte)(142)))));
            this.btnYes.FlashColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(148)))), ((int)(((byte)(138)))));
            this.btnYes.HighlightColor = System.Drawing.Color.FromArgb(((int)(((byte)(201)))), ((int)(((byte)(224)))), ((int)(((byte)(235)))));
            this.btnYes.Location = new System.Drawing.Point(198, 13);
            this.btnYes.Name = "btnYes";
            this.btnYes.Size = new System.Drawing.Size(103, 23);
            this.btnYes.TabIndex = 2;
            this.btnYes.Text = "Yes";
            this.btnYes.Click += new System.EventHandler(this.btnYes_Click);
            // 
            // Msg
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(226)))), ((int)(((byte)(236)))), ((int)(((byte)(248)))));
            this.ClientSize = new System.Drawing.Size(508, 246);
            this.ControlBox = false;
            this.Controls.Add(this.panel3);
            this.Controls.Add(this.pan2);
            this.Controls.Add(this.pan1);
            this.Font = new System.Drawing.Font("Verdana", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Msg";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.TopMost = true;
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Msg_KeyUp);
            this.pan2.ResumeLayout(false);
            this.pan2.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pb)).EndInit();
            this.pan1.ResumeLayout(false);
            this.panel3.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        

        public Msg()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.App;
            timer1.Enabled = true;
            App.MoveForm moveForm = new App.MoveForm();
            moveForm.AddControl(lbH, this);
            moveForm.AddControl(pan2, this);
        }

        #region CreateParams
        protected override CreateParams CreateParams
        {
            [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
            get
            {
                CreateParams parameters = base.CreateParams;

                if (DropShadowSupported)
                {
                    parameters.ClassStyle = (parameters.ClassStyle | 0x00020000);
                }

                return parameters;
            }
        }
        #endregion

        #region DropShadowSupported
        public static bool DropShadowSupported
        {
            get { return IsWindowsXPOrAbove; }
        }
        #endregion

        #region IsWindowsXPOrAbove
        public static bool IsWindowsXPOrAbove
        {
            get
            {
                OperatingSystem system = Environment.OSVersion;
                bool runningNT = system.Platform == PlatformID.Win32NT;

                return runningNT && system.Version.CompareTo(new Version(5, 1, 0, 0)) >= 0;
            }
        }
        #endregion


        #region ShowInfo
        public static DialogResult ShowInfo(string text)
        {
            return ShowInfo(text, MsgType.Infomation);
        }

        public static DialogResult ShowError(string text)
        {
            return ShowInfo(text, MsgType.Error);
        }

        public static DialogResult ShowWarning(string text)
        {
            return ShowInfo(text, MsgType.Warning);
        }

        public static DialogResult ShowInfo(string text, MsgType type)
        {
            string title;
            if (text.Length > 30)
            {
                title = text.Substring(0, 30) + "...";
            }
            else
            {
                title = text;
            }

            return ShowInfo(title, text, type);
        }

        public static DialogResult ShowInfo(string caption, string text, MsgType type)
        {
            Msg msg = new Msg();
            msg.lbH.Text = caption;
            msg.lbD.Text = text;
            switch (type)
            {
                case MsgType.Infomation:
                    msg.pb.Image = Properties.Resources.Inf;
                    msg.btnYes.Text = "&OK";
                    msg.btnNo.Visible = false;
                    break;
                case MsgType.Error:
                    msg.pb.Image = Properties.Resources.Err;
                    msg.btnYes.Text = "&OK";
                    msg.btnNo.Visible = false;
                    break;
                case MsgType.Help:
                    msg.pb.Image = Properties.Resources.Hlp;
                    break;
                case MsgType.Warning:
                    msg.pb.Image = Properties.Resources.Wrn;
                    break;
                default:
                    break;
            }
            return msg.ShowDialog();
        } 
        #endregion



        #region MyRegion
        private void btnYes_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.C && e.Control)
            {
                string str = "Title:";
                str += Environment.NewLine;
                str += lbH.Text;
                str += Environment.NewLine;
                str += "Content:";
                str += Environment.NewLine;
                str += lbD.Text;
                Clipboard.SetText(str);
            }
        } 
        #endregion

        private void btnYes_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
        }

        private void btnNo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (timeout < 1)
            {
                timer1.Enabled = false;
                this.DialogResult = DialogResult.Yes;
            }
            timeout--;
            lbTimeout.Text = timeout.ToString();
        }

        private void Msg_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Space)
            {
                btnYes_Click(btnYes, e);
            }
            else if (e.KeyCode == Keys.N || e.KeyCode == Keys.Escape)
            {
                btnNo_Click(btnNo, e);
            }
            else if (e.KeyCode == Keys.C && e.Control)
            {
                Clipboard.SetText(lbD.Text);
            }
            
        }

        
    }

    #region MsgType
    public enum MsgType
    {
        Infomation,
        Error,
        Help,
        Warning
    } 
    #endregion
}